package ru.narod.amidoriya.app.sushibaramidoriya;
import android.content.Context;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.*;

public class ListBludoTrash extends BaseAdapter {
	private Context mContext;
	private List<? extends Map<String, ?>> mDatatr;	
	Bitmap appdri;
	int sizes;
	int msizes;
	String mvalutt;
	String mizm;
	String pic;
	public ListBludoTrash(Context c, List<? extends Map<String, ?>> data,int sizes, String valutt, String izmm) {
		mContext = c;
		mDatatr = data;
		msizes = sizes;
		mvalutt = valutt;
		mizm = izmm;
	}

	public int getCount() {
		return mDatatr.size();
	}

	public Object getItem(int position) {
		return mDatatr.get(position);
	}

	public long getItemId(int position) {
		return position;
	}



	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		View itemlistbl;

		if (convertView == null) {
			itemlistbl = new View(mContext);
			LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
			itemlistbl = inflater.inflate(R.layout.itemlistbludotrash, parent, false);
		} else {
			itemlistbl = (View) convertView;
		}


		ImageView Ipicsmallpludo = (ImageView) itemlistbl.findViewById(R.id.ipicsmallpludotr);
		TextView Inamebludo = (TextView) itemlistbl.findViewById(R.id.inamebludotr);
		TextView Ipricebludo = (TextView) itemlistbl.findViewById(R.id.ipricebludotr);
		TextView Iweightpiudo = (TextView) itemlistbl.findViewById(R.id.iweightpiudotr);
		TextView Idostavkabludo = (TextView) itemlistbl.findViewById(R.id.idostavkabludotr);

		
		try {
			pic = mDatatr.get(position).get("tr_4").toString();
			if (pic == null) {
				pic = "";
			}
			if (pic.equals("")) {
				//Ipicsmallpludo.setImageResource(R.drawable.no_pic);
				Ipicsmallpludo.setImageURI(Uri.parse(""));
			} 
			else
			{
				
				File aboutpic = new File(mDatatr.get(position).get("tr_5").toString());
				InputStream isan = new FileInputStream(aboutpic);
				Bitmap bmSource =  BitmapFactory.decodeStream(isan);
				Bitmap bmThumbnail = ThumbnailUtils.extractThumbnail(bmSource,
						msizes, msizes);
				Ipicsmallpludo.setImageBitmap(bmThumbnail);
			}
			
		}
		catch (Exception e) {
			Ipicsmallpludo.setImageURI(Uri.parse(""));	
		}
//
		try {
			Inamebludo.setText(mDatatr.get(position).get("tr_0").toString());
		}
		catch (Exception e) {
			Inamebludo.setText("");
		}
//
		try {
			Ipricebludo.setText(mDatatr.get(position).get("tr_1").toString() + " " + mvalutt + " X "+mDatatr.get(position).get("tr_7").toString()+ " " + mizm);
		}
		catch (Exception e) {
			Ipricebludo.setText("");
		}
//
		try {
			Idostavkabludo.setText(mDatatr.get(position).get("tr_2").toString());
		}
		catch (Exception e) {
			Idostavkabludo.setText("");
		}
//
		try {
			Iweightpiudo.setText(mDatatr.get(position).get("tr_3").toString());
		}
		catch (Exception e) {
			Iweightpiudo.setText("");
		}		
		return itemlistbl;
	}


	

}
